#include "linkage.h"
#include "throw.h"
using namespace std;

	


Family::Family(family_id_t id, std::string name):
	id(id),name(name)
	{
	}

Family::~Family()
	{
	}
	


Individual* Family::findIndividualById(individual_id_t indi)
	{
	std::map<individual_id_t,Individual*>::iterator r= id2individual.find(indi);
	if(r==id2individual.end()) return NULL;
	return r->second;
	}
Individual* Family::findIndividualByName(const std::string name)
	{
	std::map<string,Individual*>::iterator r= name2individual.find(name);
	if(r==name2individual.end()) return NULL;
	return r->second;
	}
	
void Family::put(Individual* indi)
	{
	if(indi->family!=this) THROW("not the same family");
	this->id2individual.insert(make_pair<individual_id_t,IndividualPtr>(indi->id,indi));
	this->name2individual.insert(make_pair<string,IndividualPtr>(indi->name,indi));
	}


std::ostream& operator<<(std::ostream& out,const Family& o)
    {
    out << o.name;
    return out;
    }

Individual::Individual(
	individual_id_t id,
	Family* family,
	std::string name,
	string father,
	string mother,
	Gender gender,
	phenotype_t status
	):
	id(id),family(family),name(name),
	father(father),
	mother(mother),
	gender(gender),status(status)
	{
	}

Individual::~Individual()
	{
	}

std::ostream& operator<<(std::ostream& out,const Individual& o)
    {
    if(o.family!=NULL) out << o.family->name << "\t";
    out << o.name
	    << "\t"<< o.father
	    << "\t" << o.mother
	    << "\t" << o.gender
	    << "\t" << o.status;
    return out;
    }
